package com.itheima.mm.mapper;

import com.itheima.mm.entity.CatalogPageQueryParams;
import com.itheima.mm.pojo.Catalog;
import com.itheima.mm.vo.CatalogVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Description CatalogMapper
 * @Author yunchuan
 * @Date 2024-06-26
 */
@Mapper
public interface CatalogMapper {

    //预览试题相关
    @Select("select * from t_catalog where id = #{id}")
    Catalog getById(Integer id);






@Select("select * from t_catalog where course_id = #{courseId}")
    List<Catalog> findListByCourseId(Integer courseId);

    /**
     * 添加学科目录
     * @param catalog
     */
    @Insert("INSERT INTO t_catalog (name, create_date, status, user_id, course_id)\n" +
            "VALUES (#{name},#{createDate},#{status},#{userId},#{courseId})")
    void add(Catalog catalog);

    //根据条件查询学科目录
    List<CatalogVO> findByCondition(CatalogPageQueryParams queryParams);

    //删除学科目录
    @Delete("delete from t_catalog where id = #{id}")
    void delete(Integer id);

    //修改学科目录
   @Update("UPDATE t_catalog SET name=#{name}, status=#{status}, user_id=#{userId} WHERE id=#{id}")
    void update(Catalog catalog);

    //禁用学科目录
    @Update("UPDATE t_catalog SET status = #{status} WHERE id = #{id}")
    int updateCatalogStatus(@Param("id") Integer id, @Param("status") Integer status);


}
